2013-10-20 31 views
0

因此,我正在爲此工作幾個小時,並且我無法找到正確的算法,如何在textarea的值更改時更新函數的參數。更新textarea函數參數onblur

<script> 
    details = ""; 
    postid = <? php echo $_GET['id']; ?> ; 
    userid = <? php echo User::GetUserID($_SESSION['username']); ?> ; 
    postedby = posted_by; 

    function offerIt() { 
     //created a function so that we can get the latest value of the textarea because at first it was giving the default value which was null because at the page load the value is null of the textarea 
     addPostOffer('' + details + ',' + postid + ',' + userid + ',' + postedby + ''); 
    } 
</script> 
<textarea placeholder="Type in you offer details" rows="5" class="input-block-level" id="offer_details" onblur="details=this.value"></textarea> 
<script> 
    document.write("<input type='submit' class='btn btn-primary pull-right' onclick='offerIt()' value='Offer It' />"); 
</script> 

所以實際上我想要details變量得到更新。首先我將它的值設置爲「」,然後onblur textarea(#offer_details)的值,但現在我希望addPostOffer的參數也被更新,但是這沒有發生!我怎樣才能做到這一點?

這裏還有什麼document.write寫着:

<input type="submit" class="btn btn-primary pull-right" onclick="offerIt()" value="Offer It"> 

請幫助。

+0

嘿,只是好奇,這是解決在下面的答案幫助? –

回答

0

我測試你的代碼,問題就在這裏:

postid = <? php echo $_GET['id']; ?> ; 
userid = <? php echo User::GetUserID($_SESSION['username']); ?> ; 

這應改爲:

postid = "<?php echo $_GET['id']; ?>"; 
userid = "<?php echo User::GetUserID($_SESSION['username']); ?>"; 

整個代碼現在變成,我加posted_by =用戶標識;定義它:

<script> 
    details = ""; 
    postid = "<?php echo $_GET['id']; ?>"; 
    userid = "<?php echo User::GetUserID($_SESSION['username']); ?>"; 
    posted_by = userid; 
    postedby = posted_by; 

    function offerIt() { 
     //created a function so that we can get the latest value of the textarea because at first it was giving the default value which was null because at the page load the value is null of the textarea 
     addPostOffer('' + details + ',' + postid + ',' + userid + ',' + postedby + ''); 
    } 
</script> 
<textarea placeholder="Type in you offer details" rows="5" class="input-block-level" id="offer_details" onblur="details=this.value"></textarea> 
<script> 
    document.write("<input type='submit' class='btn btn-primary pull-right' onclick='offerIt()' value='Offer It' />"); 
</script>