Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

AJAX Help

Featured Replies

Hello I have a problem with passing through a value which was in a select box and ive tried many different ways but I haven't got a clue what the problem is.

 

here is the ajax/javascript:

 

function validate(){
var ADV_Title = document.getElementById('ADV_Title').value;
var ADV_Text = document.getElementById('ADV_Text').value;
var ADV_Image = document.getElementById('ADV_Image').value;
var el = document.getElementById('Permission_ID');
var result = [];
var options = el && el.options;
var opt;
for (var i=0, iLen=options.length; i<iLen; i++)
{
opt = options;
if (opt.selected) {
result.push(opt.value);
}
}
if (ADV_Title == "" || ADV_Text == "" || ADV_Image == "" || result == ""){
alert("One of the forms are missing data. Please refill the form.");
} else{
alert("Results are : " + ADV_Title + ADV_Text + ADV_Image + result);
}
//AJAX ----------------------------------------------------------------------
var xmlhttp;
if (window.XMLHttpRequest)
{
//code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{
// code for IE6, IE5
xmlhttp=new
ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var responce_str = xmlhttp.responseText;
if (responce_str!="")
{
}
}
};
xmlhttp.open("GET","new_advert.php"+
"?PHPSESSID=<?php echo $_GET['PHPSESSID'];?>"+
"&ADV_Title=" + ADV_Title+ "&ADV_Text=" + ADV_Text + "&ADV_Image="+ ADV_Image +"&Permission_ID" + result +
"&action=get_app",true);
xmlhttp.send();
alert(result); // testing the value
//AJAX ----------------------------------------------------------------------
}
my html:
<table>
<tr>
<td>Title:<span style="color:red;">*</span></td>
<td><input type="text" id="ADV_Title"/></td>
</tr>
<tr>
<td>Content:<span style="color:red;">*</span></td>
<td>
<textarea style=" width:600px;
border-radius:3px;
border:none;
padding:5px;
background-color:#e7e7e7;
"
id="ADV_Text" placeholder="Please put your content here....."></textarea>
</td>
</tr>
<tr>
<td>Background Image:<span style="color:red;">*</span></td>
<td><input type="text" id="ADV_Image"/></td>
</tr>
<tr>
<td>Who would this advert be assigned to?:<span style="color:red;">*</span></td>
<td><select id="Permission_ID" multiple>
<option value="0">Please Select A User Type......</option>
<?php
$userlist_query = "
SELECT UST_ID, UST_Name
FROM tbl_sys_User_Types
WHERE USR_ID = 1
";
$userlist = mysql_query($userlist_query);
while($result = mysql_fetch_array($userlist)){
echo '<option value="'.$result['UST_ID'].'">'.$result['UST_Name'].'</option>';
}
?>
</select></td>
</tr>
<tr>
<td></td>
<td><span style="color:#797979;">Note: You can select multiple users.</span></td>
</tr>
<tr>
<td></td>
<td><input type="button" onclick="validate()" value="Create Advert"/></td>
</tr>
</table>
this is the php:
if ($user_id!="" && @$_GET["action"]=="get_app")
{
$ADV_Title = @$_GET["ADV_Title"];
$ADV_Text = @$_GET["ADV_Text"];
$ADV_Image = @$_GET["ADV_Image"];
$result = @$_GET["Permission_ID"];
$insert_advert = mysql_query("
INSERT INTO tbl_ADV_Adverts (ADV_Title,ADV_Text,ADV_Image,Permission_ID)
VALUES ('$ADV_Title','$ADV_Text','$ADV_Image','$result')"
);
"SELECT MAX(ADV_ID) AS ID
FROM Advert_table
";
//for()
//{
//"INSERT INTO permissions (USR_ID, ADV_ID)
//VALUES ($USR_ID, $ADV_ID)";
//}
}
else
{
echo "failure";
}
maybe it just needs a fresh pair of eyes to note out what ive done wrong because it sends through all the other values apart from the result variable.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.