PDA

View Full Version : Append Javascript



sudjo
04-28-2008, 05:12 AM
Hi all,
I have a simple problem, but I can't seem to figure this out for the life of me.

Problem:
1. Using Javascript and PHP
2. Move values from onClick links to text boxes
3. Want to call the function (superpaste) to create a custom sql statement. Every thing works other than the calling of the superpaste function and its workings.

http://utite.org/resumeinfo/easysql.php#


function superpaste(){
var writingblock = document.myQueryForm.query;
var degree = document.first_form.degree.value;
var interest = document.first_form.interest.value;
var region = document.first_form.region.value;
var experience = document.first_form.experience.value;
var writingblock.value = "Select * from Resume WHERE degree_program = '";
var writingblock.value =+ degree;
var writingblock.value =+ "' AND interest = '";
var writingblock.value =+ interest;
var writingblock.value =+ "' AND region ='";
var writingblock.value =+ region;
var writingblock.value =+ " ' AND experience = '";
var writingblock.value =+ experience;
var writingblock.value =+ "' ;";
}
}








//////////////////////////////////////////////////////////////////////////////////
/*
This function tests to see if something has been entered in the query.
If empty then an alert box appears and the form submission is halted
*/
function isQuery() {
var myForm = document.myQueryForm;
if ( myForm.query.value == 0 ) {
alert("There is no query.\nPlease enter a query.");
myForm.query.focus();
return false;
}
return true;
}
// -->
</script>
<!-- END OF JAVASCRIPT FUNCTIONS FOR ALL easysql.php RELEASES -->
<META name="ROBOTS" content="NOINDEX,NOFOLLOW">
<style type="text/css">
<!--
.style1 {
color: #CC5500;
font-weight: bold;
}
-->
</style>
</HEAD>
<BODY>
<td align="left"><p class="style1">Candidate Profile Builder:</p>
<p><strong>Degree:</strong>

<a href="#" onClick="document.first_form.degree.value='Undergraduate';">Undergraduate[/url]
<a href="#" onClick="document.first_form.degree.value='MBA';">MBA[/url]
<a href="#" onClick="document.first_form.degree.value='PhD';">Ph D[/url]
<p><strong>Looking For:</strong>

<a href="#" onClick="document.first_form.interest.value='Internship';">Internship[/url]
<a href="#" onClick="document.first_form.interest.value='Part Time';">Part Time[/url]
<a href="#" onClick="document.first_form.interest.value='Full Time';">Full Time[/url]

</p>
<p><strong>Where</strong>:

<a href="#" onClick="document.first_form.region.value='Texas';">Texas and Surrounding Area[/url]
<a href="#" onClick="document.first_form.region.value='North';">North[/url]
<a href="#" onClick="document.first_form.region.value='South';">South[/url]
<a href="#" onClick="document.first_form.region.value='West';">West[/url]
<a href="#" onClick="document.first_form.experience.value='East';">East[/url]
<p><strong>Relevant Work Experience:</strong>

<a href="#" onClick="document.first_form.region.value='<=1';">1 or Less[/url]
<a href="#" onClick="document.first_form.experience.value='<=2 AND >= 1';">1-2 Years[/url]
<a href="#" onClick="document.first_form.experience.value='>=2';">2+ Years[/url]
<a href="#" onClick="superpaste()">YES[/url]

<p><strong>My Candidate:
</strong>
<form name="first_form">
<input name="degree" type="text" id="degree">
<input name="interest" type="text" id="interest">
<input name="region" type="text" id="region">
<input name="experience" type="text" id="experience">

</form>

jscheuer1
04-28-2008, 12:40 PM
Actually there are other problems with the page, but perhaps you were messing around with it since you posted. The superpaste function should be:


function superpaste(){
var writingblock = document.myQueryForm.query;
var degree = document.first_form.degree.value;
var interest = document.first_form.interest.value;
var region = document.first_form.region.value;
var experience = document.first_form.experience.value;
writingblock.value = "Select * from Resume WHERE degree_program = '";
writingblock.value += degree;
writingblock.value += "' AND interest = '";
writingblock.value += interest;
writingblock.value += "' AND region ='";
writingblock.value += region;
writingblock.value += " ' AND experience = '";
writingblock.value += experience;
writingblock.value += "' ;";
}

Aside from the obvious changes (dropped the redundant and illegal multiple var declarations) I also reversed =+ to +=. The former is math assignment meaning literally:

equals positive

The later (when valid) is concatenation or addition, depending upon the values. If strings, as is the case here, concatenation.

And finally, perhaps least obvious, I dropped an extra closing curly bracket:

}

from the end of the function.

Now another thing wrong with the page is this (its onclick event is so full of errors that it is basically meaningless in javascript):


<input type="button"
onclick="Select * from Resume WHERE degree_program = 'document.first_form.degree.value' AND interest = 'document.first_form.interest.value' AND region ='document.first_form.region.value' AND experience = 'document.first_form.experience.value';"
value="Call function">

It probably should be (now that superpaste works):


<input type="button"
onclick="superpaste();"
value="Call function">

There still could be other issues.