1

I have a page with following code:

'customCode' => 'input name="last_name" id="last_name" size="25" maxlength="25" type="text" value="{$fields.last_name.value}"'

I want to run a script that will add onblur="name_valid(this.value);" after name="last_name"

Resulting Output should be like

'customCode' => 'input name="last_name" onblur="name_valid(this.value);" id="last_name" size="25" maxlength="25" type="text" value="{$fields.last_name.value}"
1
  • 1. What have you tried? 2. I assume adding onblur=... at the end of string doesn't change anything. Commented Feb 24, 2014 at 5:56

2 Answers 2

2

How about this,

$string = 'input name="last_name" id="last_name" size="25" maxlength="25" type="text" value="{$fields.last_name.value}"';

echo $string = str_replace('name="last_name"', 'name="last_name" onblur="name_valid(this.value);" ', $string);
Sign up to request clarification or add additional context in comments.

Comments

-1

A simple string replace will do it.

<?php 
$input_str = '<input name="last_name" id="last_name" size="25" maxlength="25" type="text" value="{$fields.last_name.value}>'; 
$new_str= str_replace('name="last_name" ','name="last_name" onblur="name_valid(this.value);" ',$input_str);
echo $new_str; 
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.