Solved

Javascript onsubmit script / string

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add Clickable Links to Google Map Markers 3 29
HTML5 frame 5 25
JQuery JavaScripot loop though RadioButtonList 4 25
Html CheckBox obtain Its Value 5 14
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
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…

809 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