Dynamic form content: remove http://

I have a text field for a user to enter a URL. When I call the form data with PHP I’m adding the http:// into the link like this: <a href=“http://’ . $url . '”>

I’m wondering if javascript can help me check to see if the user has entered the http:// and if so, remove it.


if (document.getElementById("some_input_field").value.substring(0,7) == "http")
{
  document.getElementById("some_input_field").value = document.getElementById("some_input_field").value.substring(7);
}

Where “some_input_field” is the id of the input field.

Thanks for the code idea ScallioXTX. I’m pretty new to working JS into my page like this. Would you mind explaining the code a bit?

Oops, just saw I made an error …
It’s supposed to be


if (document.getElementById("some_input_field").value.substring(0,7) == "http://")
{
  document.getElementById("some_input_field").value = document.getElementById("some_input_field").value.substring(7);
}

Basically it checks if the first 7 characters form the character sequence http:// and if does, remove the first 7 characters from the input field. The first 7 characters are of course http:// so you remove that.