2015年4月11日 星期六

ScriptCase 裡配合Javascript製作一個button的方法範例

很好的參考範例:

http://www.scriptcase.net/forum/showthread.php?7633-Best-way-to-do-this-in-Scriptcase-Display-Nicely-as-one-field-edit-as-multiple


Block1: 2 Label fields ({myaddress}, {mybtn}).

Block2: Address fields.

Create a javascript method (switchBlocks) with a variable (vswitch) to be passed in.

Code:
if(vswitch == 1)
{
document.getElementById('div_hidden_bloco_0').style.display = 'none'; //you need to determine the number of the block by inspecting the element in the browser
document.getElementById('div_hidden_bloco_1').style.display = 'block';
}
else
{
document.getElementById('div_hidden_bloco_0').style.display = 'block';
document.getElementById('div_hidden_bloco_1').style.display = 'none';
}
Create a php method (call_switchBlocks):
Code:
sc_ajax_javascript('switchBlocks',array(0)); //we need this because we can't call javascript from the onLoad event
onLoad:
Code:
{myaddress} = {name}.'<br>'.{address1}.'<br>'.{city};
{mybtn} =  "<button type='button' onclick='switchBlocks(1)'>Edit</button>"; //could be beefed up with some css
call_switchBlocks();
onAfterUpdate:
Code:
call_switchBlocks();
That should give you a start.

另一個案例:

自行建立欄位:{sam_addr_btn}

在 onLoad Event裡建立
{same_addr_btn1}="<button type='button' onclick='sameaddress1()'>Same Address</button>";
在 Javascript Methods建立一個 sameaddress
code:
$("select[name$='m_country_id']" ).val($("select[name$='country_id']").val()); 
$("input[name$='m_state']" ).val($("input[name$='state']").val()); 
$("input[name$='m_city']" ).val($("input[name$='city']").val()); 
$("input[name$='m_postcode']" ).val($("input[name$='postcode']").val()); 
$("input[name$='m_street1']" ).val($("input[name$='street1']").val());
$("input[name$='m_street2']" ).val($("input[name$='street2']").val());



沒有留言:

張貼留言

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。