?
Solved

Embedding HTML into Javascript

Posted on 2008-11-19
2
Medium Priority
?
353 Views
Last Modified: 2012-05-05
HI there im trying to embd some HTML, specifically an input box and a date picker into a javascript call so that when a user clicks a link it dynamically generates the form elements to the screen. The generation seems to work fine however when I click the datepicker box to bring up the pop up it gives me an javascript error.

Error: syntax error
Source File: http://ictintranet/commsform/defaultnew.asp
Line: 1, Column: 9
Source Code:
winBRopen(

I have included all the code in the below attatchment so you can test.

Any help is always appreciated.
//Javascript fuction
function addInput(divName){
    
var newdiv = document.createElement('div');
newdiv.innerHTML = "<textarea cols='50' rows='3' name='event[]'>";
newdiv.innerHTML = newdiv.innerHTML + "<input type='text' name='fromdate[]' maxlength='10' size='20'><a href='javascript:;' onClick='winBRopen('cal_popup.asp?FormName=FormName&amp;FieldName=eventdate&amp;','popup_cal','241','206','no','no')'><img src='img/cal.gif' alt='Pick A Date' border='0' class='DatePicker' align='middle'/></a>";
document.getElementById(divName).appendChild(newdiv);
 
}
 
//HTML
 
<input type="button" value="Add another text input" onClick="addInput('dynamicInput');">

Open in new window

0
Comment
Question by:MayoorPatel
2 Comments
 
LVL 5

Accepted Solution

by:
vibrazy earned 2000 total points
ID: 22994339
Try this

<script>
//Javascript fuction
function addInput(divName){
    
var newdiv = document.createElement('div');
newdiv.innerHTML = "<textarea cols='50' rows='3' name='event[]'>";
newdiv.innerHTML = newdiv.innerHTML + "<input type='text' name='fromdate[]' maxlength='10' size='20'><a href='javascript:;' onClick=\"winBRopen('cal_popup.asp?FormName=FormName&amp;FieldName=eventdate&amp;','popup_cal','241','206','no','no')\"><img src='img/cal.gif' alt='Pick A Date' border='0' class='DatePicker' align='middle'/></a>";
document.getElementById(divName).appendChild(newdiv);
 
}
 </script>

Open in new window

0
 
LVL 1

Author Closing Comment

by:MayoorPatel
ID: 31518233
Awesome worked a treat
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Question has a verified solution.

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

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…
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…
Suggested Courses

569 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