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?
Bookmarks