PDA

View Full Version : innterHTML disappears so fast



erhan.ozden
06-18-2008, 06:12 PM
when you click "kontrol et " button the message "alan boş olamaz" loading and disappears so fast,how can i make it stay...

innerHMTL --> ad_kontrol.innerHTML="<img src=\"yukleniyor.gif\" />alan boş olamaz!";

thank you very much ...


<script>

function carp(form){

var s1=form.ilk_sayi.value;
var s2=form.ikinci_sayi.value;
var sonuc;

//rakamlari kontrol et

if(isNaN(s1) || isNaN(s2) ){
alert('geçersiz sayi');
}
else{
//eval ile isleme sok busayade sayilar tamsayi olacak
carp= eval(s1) * eval(s2);

//cevap alanini olustur

form.cevap.value=carp;
}
}
</script>

<style>
#ad_kontrol{
padding-left:6px;
color:#FF0000;
}
</style>
</head>

<body>
<script>
function ad_alan_kontrol(form){

//ad metin alanini kontrol et
if(form.ad.value==""){
var ad_kontrol=document.getElementById('ad_kontrol');
ad_kontrol.innerHTML="<img src=\"yukleniyor.gif\" />alan boş olamaz!";
}
}
</script>
<form id="form" name="form1" method="post" action="">

adınız:
<input type="text" name="ad" /><span id='ad_kontrol'></span><p>
<label>
<input type="submit" name="Submit" onclick='ad_alan_kontrol(this.form)' value="kontrol et" />
</label>
<p>iki sayı girin:</p>
<p>ilk sayı:
<input type="text" name="ilk_sayi" />
</p>
<p>ikinci sayı:
<input type="text" name="ikinci_sayi" />
</p>
<p>
<input type="submit" name="Submit2" onclick='carp(this.form)' value="ÇARP" />
</p>
<p>sonuç:
<input type="text" name="cevap" />
</p>
<p>
<input type="reset" name="Submit3" value="Temizle" />
</p>
</form>

boogyman
06-18-2008, 06:53 PM
if its a temporary element meant to only run while the script is being processed, then it would be wise to not "delay" the page from actually processing and/or displaying the contents accordingly

erhan.ozden
06-18-2008, 10:28 PM
may you show with a fugitive script(example)?

rangana
06-19-2008, 01:05 AM
It's because you are using the submit button. By default, the submit button, submits the form which reloads the page then.
The fix is by changing the highlighted to button instead:


<input type="submit" name="Submit" onclick='ad_alan_kontrol(this.form)' value="kontrol et" />


Hope it helps.

erhan.ozden
06-19-2008, 01:42 AM
it works :) .. thank you very much ..