Dynamically Changing src Attribute of script

I had a situation where I wanted to change the src of a script dynamically before the script runs.
Given the following code, we needed to change src before the script gets executed:

        <script language="JavaScript" type="text/javascript" src="..."></script>

So simply (This simply took a couple of hours!) I did this:

<script language="JavaScript" type="text/javascript">
    url = ....
    function staticLoadScript() {
            document.write('<script language="JavaScript" type="text/javascript" src="', url, '"><\/script>');


setTimeout() triggers expression only once but setInterval() keeps triggering expression again and again (unless you tell it to stop).

window.setInterval(function showAnn(){/*do something*/ },3000);

Stop submit with js

function test(){

    if(document.getElementById('postalRate').value== '') {
        alert("calculate rate") ;
    else window.location = "purchase.htm?method=showPurchaseSummary";

<input type="button" onclick="test();" value="Buy It Now"/>

Submit a form using js

document.myform.submit(); where myform is the form name.


function confirmDel(){
    var answer = confirm("delete?")
    if (answer){
        window.location = "..."


Submit different actions in one form

function submitThis(target){
    if(target == 'free')     document.myform.action="newAd.htm?method=saveFreeAd";
    if(target == 'pay')     document.myform.action="newAd.htm?method=payNow";
    if(target == 'save')     document.myform.action="newAd.htm?method=saveAndPayLater";
    if(target == 'preview') document.myform.action="newAd.htm?method=previewAd";

<form:form method="post" name="myform">
    <input type="button" value="Save Free Ad"         onclick="javascript:submitThis('free')"/>
    <input type="button" value="Pay Now"             onclick="javascript:submitThis('pay')"/>
    <input type="button" value="Save and Pay Later" onclick="javascript:submitThis('save')"/>
    <input type="button" value="Preview"             onclick="javascript:submitThis('preview')"/>
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License