Solved

Javascript onsubmit script / string

Posted on 2016-07-20
3
64 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
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 42

Accepted Solution

by:
Rob Jurd, EE MVE earned 500 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 1

Author Closing Comment

by:erzoolander
ID: 41723729
Thanks!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now