Left_blank
08-20-2010, 04:34 PM
I have a function to create a string of parameters using jquerys serialize() method.
First I get all the text inputs, add radio elements and select elements. Then I run through them and sanitize them (the document.write is just for testing). Then at the end I serialize them.
function getQueryString(){
var fields = $('input[type=text]').add('input:checked').add(':selected').clone();
size = fields.length;
for (i=0 ; i< size ; i++){
document.write(fields[i].value, fields[i].name, '<br/>');
fields[i].value = sanitize(fields[i].value);
}
query = fields.serialize();
return query;
}
For some reason though, when I document.write the name of the select fields, it doesn't seem to have one (undefined). Even though it does have a name in the html.
<select name="month">
<option value="1" selected="selected" >January</option>
<option value="2">Febuary</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
...
</select>
The process works fine for all the other elements. Any idea how I can fix this?
First I get all the text inputs, add radio elements and select elements. Then I run through them and sanitize them (the document.write is just for testing). Then at the end I serialize them.
function getQueryString(){
var fields = $('input[type=text]').add('input:checked').add(':selected').clone();
size = fields.length;
for (i=0 ; i< size ; i++){
document.write(fields[i].value, fields[i].name, '<br/>');
fields[i].value = sanitize(fields[i].value);
}
query = fields.serialize();
return query;
}
For some reason though, when I document.write the name of the select fields, it doesn't seem to have one (undefined). Even though it does have a name in the html.
<select name="month">
<option value="1" selected="selected" >January</option>
<option value="2">Febuary</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
...
</select>
The process works fine for all the other elements. Any idea how I can fix this?