Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript onsubmit script / string

Posted on 2016-07-20
3
Medium Priority
?
122 Views
Last Modified: 2016-07-21
I have an onsubmit process that looks like

<form onsubmit="return confirm('Are you sure you want to change the dates on this reservation to those new dates?');"

What I'd like to do is change that string to incorporate some text from some form fields in the document.

I tried

onsubmit="return confirm('Are you sure you want to change the dates on this reservation to '+document.getElementByID('datepicker3').value+' to '+document.getElementById('datepicker4').value');"

but alas - it didn't work nor have any of the other variations kinda similar to that.

What am I missing?  

Thanks in advance!
0
Comment
Question by:erzoolander
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 9

Expert Comment

by:lisfolks
ID: 41721975
Your statement has an extra tick mark... is that in the code? Breaking it up for readability, it looks like this:

onsubmit="
return confirm(
'Are you sure you want to change the dates on this reservation to ' +
document.getElementByID('datepicker3').value +
' to ' +
document.getElementById('datepicker4').value'
);
"

See the extra tick mark at the end of the bolded part?
0
 
LVL 43

Accepted Solution

by:
Rob earned 2000 total points
ID: 41722014
or for easier readability, move it to its own function:
<form onsubmit="return checkForm()">
...
</form>
<script>
function checkForm() {
    var dt3 = document.getElementByID('datepicker3').value;
    var dt4 = document.getElementByID('datepicker4').value;
    return confirm('Are you sure you want to change the dates on this reservation from '+dt3+' to '+dt4);
}
</script>

Open in new window

0
 
LVL 2

Author Closing Comment

by:erzoolander
ID: 41723729
Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question