1,105,242 Community Members

Help with http header building?

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

Hello guys, i've being searching for how is it possible to get value of a form element i.e selection tag that was injected by jquery be access on submitting the form.

All the form element value where posted except for the selection element that was injected with jquery. how can i append the element value to the posted query?

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

Please post your code.

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

If you're appending the element to the form it should be available on your POST without any further action. How are you adding the additional element?

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 
<select name="sectionname" id="section-name"></select>');
$.each( data, function(key, val){
    $('#section-name').append('<option value="'+key+'">'+val+'</option>');
}
Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

That's appending the options, what about the actual select field? Is this:

<select name="sectionname" id="section-name"></select>

already part of the form and you're just adding options or are you adding that to your form with jQuery as well, if so how?

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

through JQuery

$('#section-tr').append('<td >Section: </td><td class="right len"><select name="sectionname" id="section-name"></select></td>');
$.each( data, function(key, val){
$('#section-name').append('<option value="'+key+'">'+val+'</option>');
}
Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

if that table row is between your <form> and </form> tags than it should be picked up automatically for the POST data. If that's not the case you could add a little fail safe:

$("#form-id").submit(function(){
  if ($('#section-name').length == 0) {
    //It was added, append the selected value to our form
    var the_value = $("#section-name").val();
    var new_field = "<input type='hidden' name='section' value='" + the_value + "' />";
    $("#form-id").append(new_field);
  }
});

It's not ideal or pretty but if you have that table row insdie the form tags and it's not adding it to your POST data it's a doable work-around. Just swap form-id with your actual form ID

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

thanks guys but i dont understand what you mean by "Just swap form-id with your actual form ID" GliderPilot.

But is it normal that what for what you append to html content not to be posted and access through script lang. (php) except through javascript? it will be of help if anybody can throw little light on this.

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

thanks guys but i dont understand what you mean by "Just swap form-id with your actual form ID" GliderPilot.

Change $('#form-id') to reflect the id attribute on your form. You must keep the # however.

If you post your complete code, so all of the form HTML, etc, people will be able to see exactly what your page looks like and why it might not be working.

Posting one or two lines of code isn't really helpful.

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

its like you are mis understanding my problem injecting code into html form and then submitting the form not through jquery but to php file that processes it is what am having problem about anything i appended to the dom with jquery doesn't come as part of the post ($_POST) data that was send to the php file. this is the problem not apppend another element to the form afterwhich dont comeup on php side. thanks but pls help

Member Avatar
blocblue
Practically a Posting Shark
828 posts since Jan 2008
Reputation Points: 238 [?]
Q&As Helped to Solve: 162 [?]
Skill Endorsements: 16 [?]
Featured
 
0
 

That's what I understood the problem to be too.

So if you post your complete code, we might be able to ascertain why it isn't working.

Member Avatar
GliderPilot
Posting Whiz in Training
295 posts since Sep 2006
Reputation Points: 31 [?]
Q&As Helped to Solve: 48 [?]
Skill Endorsements: 14 [?]
 
0
 

Yes that's what I understood your question to be, what I'm saying is that if the select is appended the the current form properly it should already be available in your POST data without needing to do any additional work, unless you're building your own custom AJAX call, there is no way to really modify the POST data . As blocblue stated we might be able to figure out what's going on if you post the full code.

Member Avatar
hakeemtunde
Junior Poster in Training
54 posts since Dec 2007
Reputation Points: 0 [?]
Q&As Helped to Solve: 9 [?]
Skill Endorsements: 3 [?]
 
0
 

Well thanks guys am able to resolve the issue but in different way. on the form i created the select tag without options and from jquery i appended the options to it and on submitting the form php was able to access the select post variable.

on html page

<tr id="section-tr" style=background-color:#FFFF99;>
    <td id="td1">Section: </td>
    <td id="td2" class="right len"> 
    <select name="section-name" id="section-name"></select></td>
</tr>;

then append the options with jquery

$.each( data, function(key, val){
 $('#section-name')
 .append('<option value="'+key+'">'+val+'</option>')
 });
Question Answered as of 1 Year Ago by GliderPilot and blocblue
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: