...

View Full Version : document.write('<input type="button" onClick="function();">'); problem



Wizbaggd
06-03-2005, 10:17 AM
Sorry if the title may seem stupid, but it sums up the problem I am having as best I can think... here is the code I need to fix:



<script language="JavaScript">
// this script is embedded in a linked .js file
function sendMailVote(form){
var optVote = document.sendVote.vote.value;

document.sendVote.subject.value = 'Vote: ' + optVote;
document.sendVote.submit(form);
}
</script>

<script language="JavaScript">
// these html tags are just laid out for eay reading right now, in the code they are compressed to 1 line to fit in a function call: toBuff('text','more text',form); (toBuff(txt) is a document.write(txt) simplification)

toBuff('<form action="nvform.php" method="POST" name="sendVote">');
toBuff('<input type="hidden" name="subject" value="Vote: ">');
toBuff('<input type="hidden" name="success_page" value="url">');
toBuff('<input type="hidden" name="email" value="email@domain">');

toBuff('<select name="vote">');
toBuff('<option value="Option 1">Option 1</option>');
toBuff('<option value="Option 2">Option 2</option>');
toBuff('<option value="Option 3">Option 3</option>');
toBuff('</select><br>');
toBuff('<input type="button" value="Submit" onClick="sendMailVote(this.form);" name="submit">');
toBuff('</form>');


Everything writes in correctly, except the onClick="sendMailVote(this.form);" on the submit button. I cannot seem to find a work around for this.. if anyone can help it would be greatly appreciated. I cannot just write the html tags in html, I have to use the toBuff(txt); function, due to the construction of the site.

martin_narg
06-03-2005, 10:59 AM
Is this what you are looking for mate? When the form is submitted, the subject form field is populated by "Vote: " and the vote form field value.



<script language="JavaScript">
// this script is embedded in a linked .js file
function sendMailVote(){
var optVote = document.sendVote.vote.value;
document.sendVote.subject.value = 'Vote: ' + optVote;
return true;
}
</script>

<script language="JavaScript">
// these html tags are just laid out for eay reading right now, in the code they are compressed to 1 line to fit in a function call: toBuff('text','more text',form); (toBuff(txt) is a document.write(txt) simplification)

toBuff('<form action="nvform.php" method="POST" name="sendVote" onsubmit="return sendMailVote();">');
toBuff('<input type="hidden" name="subject" value="Vote: ">');
toBuff('<input type="hidden" name="success_page" value="url">');
toBuff('<input type="hidden" name="email" value="email@domain">');

toBuff('<select name="vote">');
toBuff('<option value="Option 1">Option 1</option>');
toBuff('<option value="Option 2">Option 2</option>');
toBuff('<option value="Option 3">Option 3</option>');
toBuff('</select><br>');
toBuff('<input type="submit" value="Submit" name="submit">');
toBuff('</form>');
</script>


Hope this helps!

m_n

Wizbaggd
06-03-2005, 11:30 AM
Thank you, thank you, thank you!

This works perfectly now!


greatly appreciated! :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum