Jump to content

Using JavaScript with PHP


harryuk

Recommended Posts

Hi,

I would like to use the $_POST function for the sub-category section of the form. The problem i am having is how i can do this as i am using javascript to automatically update the sub-category section when a item is selected in the category section. So where and how would i put the $_POST function so i can echo the form info including what sub-category item i selected out on my index.php page.

 

I hope that makes sense. Please help

Thank you

team = new Array(
new Array(
new Array("Toesavers", 39482304),	
new Array("Dr. Martens Industrial", 34802389),
new Array("Himalayan", 39823498),
new Array("Caterpillar", 87587343),
new Array("Timberland", 68798735)
),
new Array(
new Array("Hand Protection", 23840238),
new Array("Eye & Face Protection", 92390484),
new Array("WeatherWear", 29048203),
new Array("Head Protection", 94098230),
new Array("Hearing Protection", 39234923),
new Array("Respiratory Protection", 29345423)
),
);
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
selectCtrl.options[0].selected = true;
   }
}
<form>
<select name="Make" onchange="fillSelectFromArray(this.form.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]));">
<option value="-1" selected="selected">Select Category</option>
<option value="1">Footwear</option>
<option value="2">PPE</option>
<option value="3">Ladders</option>
</select></label>
  <label>
    Sub-Category
  <select name="Team">
  <option></option>
<option></option>
<option></option>
<option></option>
<option></option>
<option></option>
</select></label>
</form>

Link to comment
Share on other sites

well I assume you are aware that in order to use POST you need to have a form submit the data to the other page, with that said you can just auto-update those items before the submit is triggered and then you can access them :?

Link to comment
Share on other sites

Yes sorry i do have a submit button i didnt copy all of my coding.

How would you auto update???? The java script updates it when i have ftp'ed it but i need to be able to show what sub-category item i selected when i have submitted.

Link to comment
Share on other sites

Well I don't really get what's supposed to happen but I understand you have some catalog or something where users select stuff and when they select something some other stuff is autoupdated and you want this autoupdated stuff to be accessible in another page via post, is that correct?

Link to comment
Share on other sites

Yes exactly. Under the sub-category section all the option tags have no values until an item is selected on the category section. Usually you would have values already in the option tag so you can add your $_POST function in order to send all form info to another page. But in this instance i do not have any values to be able to add a $_POST function?!?!

Link to comment
Share on other sites

Sure

 

when you're setting up the page if you have some passed data from another page which you need to access in javascript you can do this

 

<? echo "<input type='hidden' id='someid' value='Received data here'/>"; ?>

 

then you access it in js like so

 

thedata = document.getElementById('someid').value

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.