Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy document.write('<input type="button" onClick="function();">'); problem

    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:

    Code:
    <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.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    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.

    Code:
    <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
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, thank you, thank you!

    This works perfectly now!


    greatly appreciated!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •