/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Pls help on this simple javascript problem

i hv this string in javascript :

x.innerHTML += “<table border=1 width=’100%’ style=’border-collapse:collapse;’><tr><th>Day</th><th>Aturcara</th></tr><tr><td align=left><input type=text value='”+((parseInt(document.getElementById(‘eventfrom’).value))+(parseInt(document.getElementById(‘aturcaracounter’).value)-1))+” / “+document.getElementById(‘eventmonth’).value+” / “+document.getElementById(‘eventyear’).value+”‘ name=’eventdate”+document.getElementById(‘aturcaracounter’).value+”‘readonly style=’border:none;’></td><td width=80% align=center id=’tdaturcara”+document.getElementById(‘aturcaracounter’).value+”‘><input type=button value=’Add Aturcara’ [B]onmousedown=addTimeline(‘eventdate’+document.getElementById(‘aturcaracounter’).value’,’eventcounter’+document.getElementById(‘aturcaracounter’).value’) [/B]style=’width:100%;’><input type=text size=2 value=0 name=’eventcounter”+document.getElementById(‘aturcaracounter’).value+”‘></td></tr></table>”;

Look at the bold sentences.. wen i add in tat my javascript doesnt work but if i remove it it works.. can someone plsss correct me on tat code there plss.. i tried everything cant find.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@scragarAug 12.2008 — [noparse] and [/noparse] are your friends, please use them.

also could you try better descriptions in future? And capitalising I and spell checking your post would be nice.

as for your problem the solution is that your calling the function rather than assigning it:
<i>
</i>
onmousedown=[b]function(){[/b]
addTimeline('eventdate'+document.getElementById('aturcaracounter').value','eventcounter' +document.getElementById('aturcaracounter').value');
[b]};[/b]
Copy linkTweet thisAlerts:
@BladezauthorAug 16.2008 — This doesnt work.

overview of this script is there will be 1 button 'Add Day' by default.

wen add day is clicked.. it will produce a table with another button the nameing for the buttons are dynamic depending on amount of click for add day.

there for, now i would like to point the dynamic generated button to do an event onclick which also points to a function tat generates something else dynamically too.

i am hving problem at the point whr the dynamic button is press tat calls a function.

[CODE]x.innerHTML += "<table border=1 width='100%' style='border-collapse:collapse;'>
<tr><th>Day</th>
<th>Aturcara</th>
</tr>
<tr>
<td align=left><input type=text value='"+((parseInt(document.getElementById('eventfrom').value))+(parseInt(document.getElementById('aturcaracounter').value)-1))+" / "+document.getElementById('eventmonth').value+" / "+document.getElementById('eventyear').value+"' [B]name='eventdate"+document.getElementById('aturcaracounter').value[/B]+"'readonly style='border:none;'>
</td>
<td width=80% align=center [B]id='tdaturcara"+document.getElementById('aturcaracounter').value+"'>[/B]
<input type=button value='Add Aturcara' [B][I]onmousedown=function(){addTimeline('eventdate'+document.getElementById('aturcaracounter').value','eventcounter'+document.getElementById('aturcaracounter').value');}; [/I][/B]style='width:100%;'><input type=text size=2 value=0 [B]name='eventcounter"+document.getElementById('aturcaracounter').value[/B]+"'></td></tr></table>";[/CODE]


[CODE]function addTimeline(tdid,evenctr){

var z = document.getElementById(tdid);
document.getElementById(eventctr).value=parseInt(document.getElementById(eventctr).value)+1;
z.innerHTML += "<table border=1 width='100%' style='border-collapse:collapse;'><tr><th>Bil.</th><th>Peralatan</th><th>Kuatiti</th><th>Tindakan</th></tr><tr><td align=center>"+document.getElementById('palatcounter').value+". </td><td width=80% align=center><textarea style='width:100%;border:none;' name='peralatan"+document.getElementById('palatcounter').value+"'></textarea></td><td valign=top align=center><input maxlength='3' style='width:100%;border:none;' type=text name='kuantiti"+document.getElementById('palatcounter').value+"' /></td><td valign=top align=center><input maxlength='6' style='width:100%;border:none;' type=text name='tindakan"+document.getElementById('palatcounter').value+"' /></td></tr></table>";
}[/CODE]


from the first script it calls this addTimeline Function to do some work ..

hope you guys understand.
Copy linkTweet thisAlerts:
@scragarAug 16.2008 — [code=php]
x.innerHTML += "<table border=1 width='100%' style='border-collapse:collapse;'>
<tr><th>Day</th>
<th>Aturcara</th>
</tr>
<tr>
<td align=left><input type=text value='"+((parseInt(document.getElementById('eventfrom').value))+(parseInt(document.getElementById('aturcaracounter').value)-1))+" / "+document.getElementById('eventmonth').value+" / "+document.getElementById('eventyear').value+"' name='eventdate"+document.getElementById('aturcaracounter').value+"'readonly style='border:none;'>
</td>
<td width=80% align=center id='tdaturcara"+document.getElementById('aturcaracounter').value+"'>
<input type=button value='Add Aturcara' onmousedown="addTimeline('eventdate'+document.getElementById('aturcaracounter').value','eventcounter'+document.getElementById('aturcaracounter').value')" style='width:100%;'><input type=text size=2 value=0 name='eventcounter"+document.getElementById('aturcaracounter').value+"'></td></tr></table>";
[/code]

or:
[code=php]
x.innerHTML += "<table border=1 width='100%' style='border-collapse:collapse;'>
<tr><th>Day</th>
<th>Aturcara</th>
</tr>
<tr>
<td align=left><input type=text value='"+((parseInt(document.getElementById('eventfrom').value))+(parseInt(document.getElementById('aturcaracounter').value)-1))+" / "+document.getElementById('eventmonth').value+" / "+document.getElementById('eventyear').value+"' name='eventdate"+document.getElementById('aturcaracounter').value+"'readonly style='border:none;'>
</td>
<td width=80% align=center id='tdaturcara"+document.getElementById('aturcaracounter').value+"'>
<input type=button value='Add Aturcara' onmousedown="addTimeline('eventdate'"+document.getElementById('aturcaracounter').value+"','eventcounter'"+document.getElementById('aturcaracounter').value+"')" style='width:100%;'><input type=text size=2 value=0 name='eventcounter"+document.getElementById('aturcaracounter').value+"'></td></tr></table>";
[/code]


one of the 2 should work.
Copy linkTweet thisAlerts:
@BladezauthorAug 17.2008 — Thank you very much for ur code... the 2nd wan did the work.. ?

ok mayb i am hustling everyone but i kinda still hv abit more problem ..

the addTimeline code works perfectly as i wanted , it does shows onmousedown = addTimeline('<dynamic variable>','<dynamic variable>');

which is suppose to trigger

[CODE]
function addTimeline(tdid,evenctr){

var z = document.getElementById(tdid);
document.getElementById('"+eventctr+"').value=parseInt(document.getElementById('+eventctr+').value)+1;
z.innerHTML += "Testing...<br>";
}
[/CODE]


but it doesnt .. can anyone tell me wat is wrong here..

from the first code...

[CODE]onmousedown="addTimeline('eventdate'"+document.getElementById('aturcaracounter').value+"','eventcounter'"+document.getElementById('aturcaracounter').value+"')" [/CODE]

which wen check on web it appears as
[CODE]onmousedown = addTimeline('<dynamic variable>','<dynamic variable>');[/CODE]

which is correct.. but wen clicked on the web..it doesnt trigger.. am not sure if my value passing is wrong ... but i dun think so if i am not mistaken.

[CODE]
function addTimeline(tdid,evenctr){

var z = document.getElementById(tdid);
document.getElementById(eventctr).value=parseInt(document.getElementById(eventctr).value)+1;
z.innerHTML += "Testing...<br>";
}
[/CODE]
Copy linkTweet thisAlerts:
@scragarAug 17.2008 — [code=php]
function addTimeline(tdid,evenctr){
var z = document.getElementById(tdid);
document.getElementById(eventctr).value=parseInt(document.getElementById(eventctr).value)+1;
z.innerHTML += "Testing...<br>";
}
[/code]
Copy linkTweet thisAlerts:
@BladezauthorAug 17.2008 — scragar thanks.. but sadly it didnt work out .. let me pass u the entire set of codes .. mayb i dunno wat the heck i am doing mistake ?..

[CODE]
===HEAD SECTION===

<script type="text/javascript">
function addTimeline(tdid,evenctr){
var z = document.getElementById(tdid);
document.getElementById(eventctr).value=parseInt(document.getElementById(eventctr).value)+1;
z.innerHTML += "Testing...<br>";
}
function addAturcara(){

var a = parseInt(document.getElementById('eventfrom').value);
var b = parseInt(document.getElementById('eventto').value);

var c = b-a;
if (c == 0){
c=1;
}
else{
c+=1;
}

var x = document.getElementById("aturcara");
document.getElementById('aturcaracounter').value=parseInt(document.getElementById('aturcaracounter').value)+1;
if (c == parseInt(document.getElementById('aturcaracounter').value)){
document.getElementById('addDay').disabled = true;
}
x.innerHTML += "<table border=1 width='100%' style='border-collapse:collapse;'><tr><th>Day</th><th>Aturcara</th></tr><tr><td align=left><input type=text value='"+((parseInt(document.getElementById('eventfrom').value))+(parseInt(document.getElementById('aturcaracounter').value)-1))+" / "+document.getElementById('eventmonth').value+" / "+document.getElementById('eventyear').value+"' name='eventdate"+document.getElementById('aturcaracounter').value+"'readonly style='border:none;'></td><td width=80% align=center id='tdaturcara"+document.getElementById('aturcaracounter').value+"'><input type=text size=2 value=0 name='eventcounter"+document.getElementById('aturcaracounter').value+"'><input type=button value='Add Aturcara' onClick="addTimeline('tdaturcara"+document.getElementById('aturcaracounter').value+"','eventcounter"+document.getElementById('aturcaracounter').value+"')" style='width:100%;'></td></tr></table>";

}
</script>

===END OF HEAD SECTION===

[/CODE]


[CODE]
===BODY SECTION===

<center><input type="button" id='addDay' onmousedown="addAturcara();" value="Add Day" style="width:35em;height:2em;"/>
<input id='aturcaracounter' name='aturcaracounter' type=text size=2 value=0><br><br>
<span id='aturcara'></span>
</center>

===END OF BODY SECTION===
[/CODE]


isnt it suppose to work ..?? i mean tho the initialization is dynamic n passing value are dynamic as its being created.. but ufortunately it doesnt seem to work ?.. i am sorry to trouble u guys.. and especially u scragar.. u hv help me alot.. tho i am making simple jus quote mistakes..

hope anyone can help me with this..
×

Success!

Help @Bladez spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...