?
Solved

Javascript onsubmit script / string

Posted on 2016-07-20
3
Medium Priority
?
115 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

752 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