www.webdeveloper.com
+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2012
    Posts
    2

    Javascript code in ASP page works partly

    Hello people. This is my first post around here. I am not very well versed in Javascript and ASP is kind of a mystery to me.

    Background: The problem I am facing concerns a survey content manager called: Survey Project 2. Its basically a web app that allows you to create and manage surveys.

    Problem: I am having problem with a Javascript which I have placed in an ASP page. Basically what this script does is take the current time and places it in an input box of the survey. Unfortunately it doesnt work.

    Javascript: This is the code of the script
    Code:
    <script type="text/javascript">
    var d = new Date();
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();
    curr_min = curr_min + "";
    if(curr_min.length == 1) {curr_min = "0" + curr_min;}
    
    var regex = /ctl00\$ctl00\$ContentPlaceHolder1\$ContentPlaceHolder1\$Question19\$_as[0-9]{5}\$\wai1104\was[0-9]{5}\$ctl01/gi;
    
    var x = document.getElementsByTagName("input");
    
    var str = x[0].name;
    
    var result = regex.exec(str);
    document.write("Time 1:" + " " + curr_hour + " : " + curr_min);
    var a = result[0];
    document.write("Time 2:" + " " + curr_hour + " : " + curr_min);
    var objName = document.getElementsByName(a).item(0);
    document.write("Time 3:" + " "+curr_hour + " : " + curr_min);
    objName.value = curr_hour + " : " + curr_min;
    </script>
    The various Time 1, Time 2, Time 3 at the end of the code I use as buoys to show me which part of the code isnt executed.

    As you see the code is basically applying values to two variables (curr_hour and curr_min), then looks for an input tag with a name which we know a pattern (we define the pattern through regular expressions). Then it takes the first result of this search and it assigns to its value attribute the combination of curr_hour and curr_min.

    The code works perfectly as a stand alone on my editor, but not on the asp form. What I noticed is that up to the "Time 1" part it works perfectly and even places the time on the page. After that nothing.

    I am not sure but I think that it might be something in the asp page preventing it.

    I could post the whole asp page code, but its huge and dont want to flood the thread, but I will add a portion of it with the various input fields and the javascript code in my next post.

    What I basically want to know is why the code doesnt work in the asp page? Is there something I didnt apply to make it compatible to ASP, or something?

  2. #2
    Join Date
    Aug 2012
    Posts
    2
    Page code (part of):

    Code:
    <table border="0" style="width:100%;">
    	<tbody>
    <tr>
    				<td><span id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_Question19"><table cellspacing="0" cellpadding="2" border="0" style="width:100%;border-collapse:collapse;table-layout:fixed;">
    					<tbody><tr>
    						<td></td>
    					</tr><tr>
    						<td></td>
    					</tr><tr class="surveyQuestion">
    						<td><span><script type="text/javascript">
    &lt;!--
    
    var d = new Date();
    
    var curr_hour = d.getHours();
    var curr_min = d.getMinutes();
    curr_min = curr_min + "";
    
    if (curr_min.length == 1)
       {
       curr_min = "0" + curr_min;
       }
    //--&gt;
    </script>
    
    'Ωρα έναρξης: <script type="text/javascript">document.write(curr_hour + " : " + curr_min);</script>10 : 03</span></td>
    					</tr><tr class="surveyAnswer">
    						<td><table cellspacing="0" cellpadding="2" border="0" style="width:100%;border-collapse:collapse;table-layout:fixed;">
    							<tbody><tr>
    								<td><table cellspacing="0" cellpadding="2" border="0" style="width:100%;border-collapse:collapse;table-layout:fixed;">
    									<tbody><tr class="surveyAnswer">
    										<td valign="top" style="width:0%;"><span id="ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_Question19__as75743__ai1104_as75743"><span class="AnswerTextRender"></span><br><input type="text" size="20" maxlength="100" name="ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder1$Question19$_as75743$_ai1104_as75743$ctl01"></span></td>
    									</tr>
    								</tbody></table></td>
    							</tr>
    						</tbody></table></td>
    					</tr>
    				</tbody></table></span></td>
    			</tr>
    </tbody></table>

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



Recent Articles